﻿
@{
	Layout = null;

	ViewBag.Title = "Index";
}
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<table>
	<tr>
		<td>
			类别：<input type="text"  value="" id="category" name="category"  />
			<input type="file" class="importFile" />
		</td>
        <td id="td1"></td>
	</tr>
</table>

<script>
   
	$("table").on("click", ".importFile", function () {
		$(this).change(function (event) {
			if ($(this).val().length) {
				var fileName = $(this).val();
				var extension = fileName.substring(fileName.lastIndexOf('.'), fileName.length).toLowerCase();

				if (extension == ".xls" || extension == ".xlsx" || extension == ".csv") {
					var data = new FormData();
					data.append('upload', $(this)[0].files[0]);
					$.ajax({
						type: "post",
						url: "/miles/ImportCardUser?category=" + $("#category").val(),
						contentType: "application/x-www-form-urlencoded; charset=utf-8",
						data: data,
						beforeSend: function (XMLHttpRequest) {
							$(".loadingLayer").show();
							$("body").css("overflow", "hidden");
                        },

						headers: {},
						cache: false,
						contentType: false, //不可缺参数
                        processData: false, //不可缺参数
                        async:false,
						success: function (req) {
							$(".loadingLayer").hide();
							$("body").css("overflow", "auto");
							if (req.Code == 1) {
                                alert("导入成功！");
                                $("#td1").html("<a href=\"" + req.Data + "\"  >点击下载</a>");
							}
							else {
								alert(req.Message);
							}
						}, complete: function (XMLHttpRequest, textStatus) {
							$(".loadingLayer").hide();
							$("body").css("overflow", "auto");
							console.log(XMLHttpRequest);
							console.log(textStatus);
						}, error: function (XMLHttpRequest, textStatus) {
							console.log(XMLHttpRequest);
							console.log(textStatus);
						}

					});
				}
				else {
					alert("格式不对");
				}
			}
		})

    })
    function downloads(url) {
      
            $("<form id='downloadFormExcel' name='downloadFormExcel' method='post'> <iframe style='display:none;' id='downloadFrameExcel' name='downloadFrameExcel'></iframe></from>").appendTo('body')[0];
               $("#downloadFormExcel").attr("action", url);
               $("#downloadFormExcel").attr("target", "downloadFrameExcel");//iframe的名字
               $("#downloadFormExcel").submit();
               $("#exportInfo").modal("hide");
               $(".loadingLayer").hide();
               $("body").css("overflow", "auto");
               window.location.reload();
    }
</script>



